package com.gitee.sidihuo.utils.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpHelper {

    private static String IP;

    public static String getIP() {
        if (IP != null && !IP.equals("")) {
            return IP;
        }
        String ip2 = getIP2();
        if (ip2 != null && !ip2.equals("")) {
            synchronized (IpHelper.class){
                IP = ip2;
            }
        }
        return IP;
    }

    private static String getIP2() {
        String hostAddress = null;
        try {
            hostAddress = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            return "";
        }
        return hostAddress;
    }



}
